<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>debounce 防抖函数</title>
    <style>
      #red {
        margin: 0 auto;
        height: 5000px;
        width: 500px;
        background: #ccc;
      }
    </style>
  </head>
  <body>
    <div id="red">
      滚动吧
    </div>
    <button class="cancel">取消</button>
    <script src="./debounce.js"></script>
    <script>

      function handler() {
        console.log(1);
      }

      let debounceFunc = debounce(handler, 500);
      const button = document.querySelector(".cancel");
      button.onclick = debounceFunc.cancel;
      window.addEventListener("scroll", debounceFunc);
    </script>
  </body>
</html>
